package calvin.study.springboot.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.Cookie;

import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ParamTestController {

	@GetMapping("/car/{id}/owner/{username}")
	public Map<String, Object> getCar(@PathVariable("id") Integer id,//获取指定路径的值（id）
									@PathVariable("username") String username,//获取指定路径的值（username）
									@PathVariable Map<String,String> pv,//获取指定路径上所有的值（id，username…）
									@RequestHeader("User-Agent") String userAgent,
                                    @RequestHeader Map<String,String> header,
                                    @RequestParam("age") Integer age,
                                    @RequestParam("inters") List<String> inters,//获取一组值（inters）
                                    @RequestParam Map<String,String> params,
                                    @CookieValue("platformsid") String ck,//获取指定cookie的值
                                    @CookieValue("platformsid") Cookie cookie//获取所有cookie的值
			) {
		
		Map<String, Object> res = new HashMap<>();
		//@PathVariable 测试
		//res.put("id", id);
		//res.put("username", username);
		//If the method parameter is Map<String,String> ,then the map is populated with all path variable names and values.
		//如果方法参数是Map，那么映射将使用所有路径变量名和值填充
		//res.put("pv", pv);
		
		//@RequestHeader 测试
		//res.put("userAgent", userAgent);
		//res.put("header", header);
		
		//@RequestParam@RequestPara
		//res.put("age", age);
		//res.put("inters", inters);
		//res.put("params", params);
		
		res.put("ck", ck);
		res.put("cookie", cookie);
		return res;
	}
	
    @PostMapping("/save")
    public Map<String,Object> postMethod(@RequestBody String content){
        Map<String,Object> map = new HashMap<>();
        map.put("content",content);
        return map;
    }
	
	

}
